function validate_profile_form(){
	var f  = $("#profile_form");
	var p = $("#password").val();
	var p1 = $("#password_new_1").val();
	var p2 = $("#password_new_2").val();
	$(".erase_errors").remove();
	if((p.length >= 4 && p1.length >= 4 && p1 == p2) || p1.length <= 0){
		return true
	}else{
		if(p1.length < 4)
			$('<label for="title" generated="true" class="error erase_errors" style="">Minimum length is 4 characters.</label>').insertAfter("#password_new_1");
		if(p1 != p2)
			$('<label for="title" generated="true" class="error erase_errors" style="">Password Doesn\'t match.</label>').insertAfter("#password_new_2");
		if(p.length == 0){
			$('<label for="title" generated="true" class="error erase_errors" style="">Please provide Current Password.</label>').insertAfter("#password");
		}else if(p.length < 4){
			$('<label for="title" generated="true" class="error erase_errors" style="">Current Password is not correct.</label>').insertAfter("#password");
		}
		$("[href=#tabs-2]").click();
		return false;
	}
}
$("#profile_form").submit(function(e){
	e.preventDefault();
	var id = $(this).attr('id');
	var request = $(this).attr('request');
	var url = $(this).attr('action')+'?r='+request;
	var method = $(this).attr('method');
	var data = $(this).serializeArray();
	window.formNeedSubmit = $("#"+id);
	window.ajax = $.ajax({
        type: method,
        url: url,
        data: data,
        beforeSend: function (xhr) {
        	window.submitOldText = $("button#submit span").html();
	    	$("button#submit span").html("Please wait....").parent().prop("disabled", true);
	  	},
        success: function(data) {
        	window.data = data;
        	$("button#submit span").html(window.submitOldText).parent().prop("disabled", false);
        	if((data[0]['data'] === undefined) || ($.type(data) == "string")){
        		var data = new Array();
        		data[0] = {'error': 500,'data': 'Internal Error, Please call Administrator!\n<!-- SystemErrorDetails: ' + window.data + '-->'};
        	}
        	$.each(data, function(index, value) {
        		if(value['error']){
        			console.log("Error: " + value['error'] + "\nData: " + value['data'] + "\n");
        			insertStickyError(value['data'],value['error']);
        		}else{
        			window.formNeedSubmit = '';
        			insertAutoSuccess(value['data']);
        		}
			});
			$('html, body').animate({scrollTop: $("#ajax_result").offset().top});
        }
    });
});